<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<script>
    let h = document.querySelector("h1");
    let count=0;
    //开启定时器
    let timer = setInterval(f,1000);
    function f() {
        console.log(count++);
        h.innerText = count;
        if (count==3){
            //停止定时器
            clearInterval(timer);
        }
    }
    //开启定时器
     setInterval(function () {
        console.log("===")
    },2000);
    //开启只执行一次的定时器
    setTimeout(function () {
        alert("时间到!");
    },3000);

</script>
</body>
</html>